/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SmtpTriggerConfigurationPanel.java
 *
 * Created on 2012-01-17, 15:14:50
 */

package Visual.Triggers;

import Tools.CharsetControl;
import Tools.ConfigurationManager;
import Triggers.*;
import Tools.ToolBox;
import Visual.Tools.DocumentAdapter;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 *
 * @author pawelkn
 */
public class SmtpTriggerConfigurationPanel extends javax.swing.JPanel {
    private static ResourceBundle bundle;

    private SmtpTrigger smtpTrigger;

    /** Creates new form SmtpTriggerConfigurationPanel */
    public SmtpTriggerConfigurationPanel(SmtpTrigger smtpTrigger) {
        this.smtpTrigger = smtpTrigger;
        
        Locale locale = new Locale(ConfigurationManager.load().getLocale());
        ResourceBundle.clearCache();
        bundle = ResourceBundle.getBundle("Bundle", locale, new CharsetControl());        

        initComponents();

        serverPortTextField.getDocument().addDocumentListener( new DocumentAdapter() {
            @Override
            public void update() {
                ToolBox.tryParseIntPositive(serverPortTextField);
            }
        });
    }

    public String getAccountName() {
        return accountNameTextField.getText();
    }

    public void setAccountName(String accountName) {
        this.accountNameTextField.setText(accountName);
    }

    public String getReceiverEmail() {
        return receiverEmailTextField.getText();
    }

    public void setReceiverEmail(String SendTo) {
        this.receiverEmailTextField.setText(SendTo);
    }

    public String getMessage() {
        return textArea.getText();
    }

    public void setMessage(String textArea) {
        this.textArea.setText(textArea);
    }

    public String getTitle() {
        return titleTextField.getText();
    }

    public void setTitle(String Title) {
        this.titleTextField.setText(Title);
    }

    public String getPassword() {
        return new String(passwordField.getPassword());
    }

    public void setPassword(String password) {
        this.passwordField.setText(password);
    }

    public String getSenderEmail() {
        return senderEmailTextField.getText();
    }

    public void setSenderEmail(String senderEmail) {
        this.senderEmailTextField.setText(senderEmail);
    }

    public String getServerName() {
        return serverNameTextField.getText();
    }

    public void setServerName(String serverName) {
        this.serverNameTextField.setText(serverName);
    }

    public int getServerPort() {
        try {
            return Integer.parseInt( serverPortTextField.getText() );
        } catch(Exception e) {
            return 0;
        }
    }

    public void setServerPort(int serverPort) {
        this.serverPortTextField.setText(Integer.toString(serverPort));
    }

    public SmtpTrigger getSmtpTrigger() {
        return smtpTrigger;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        serverNameTextField = new javax.swing.JTextField();
        serverPortTextField = new javax.swing.JTextField();
        senderEmailTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        accountNameTextField = new javax.swing.JTextField();
        passwordField = new javax.swing.JPasswordField();
        receiverEmailTextField = new javax.swing.JTextField();
        titleTextField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        textArea = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(400, 351));
        setRequestFocusEnabled(false);

        jLabel1.setText(bundle.getString("SMTP SERVER NAME:")); // NOI18N

        jLabel2.setText(bundle.getString("PORT FOR SSL:")); // NOI18N

        jLabel3.setText(bundle.getString("SENDER EMAIL:")); // NOI18N

        jLabel7.setText(bundle.getString("ACCOUNT NAME:")); // NOI18N

        jLabel8.setText(bundle.getString("PASSWORD:")); // NOI18N

        jLabel10.setText(bundle.getString("TITLE:")); // NOI18N

        textArea.setColumns(20);
        textArea.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
        textArea.setRows(5);
        jScrollPane4.setViewportView(textArea);

        jLabel4.setText(bundle.getString("RECEIVER EMAIL:")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(titleTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1))
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(serverNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                            .addComponent(senderEmailTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                            .addComponent(receiverEmailTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                            .addComponent(passwordField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                            .addComponent(accountNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                            .addComponent(serverPortTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(serverNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(serverPortTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(accountNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(senderEmailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(receiverEmailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField accountNameTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.JTextField receiverEmailTextField;
    private javax.swing.JTextField senderEmailTextField;
    private javax.swing.JTextField serverNameTextField;
    private javax.swing.JTextField serverPortTextField;
    private javax.swing.JTextArea textArea;
    private javax.swing.JTextField titleTextField;
    // End of variables declaration//GEN-END:variables

}
